package com.example.content.adapter.recycle.entity

import com.example.content.adapter.recycle.FunAction
import com.example.content.repository.bean.ProductInfo
import com.example.content.repository.bean.RecommendItem
import com.example.content.repository.bean.UserInfo

/**
 * Created by zhudongao
 * Desc
 * Date 2020/10/4
 */
class HomeItemEntity(val type:Int, val recommendItem: ProductInfo) : ItemEntity<ProductInfo>(type, recommendItem) {

    var funAction: FunAction? = null
    var userId = -1
    var id = -1
    var viewNum: Int = 0
    var isCollect: Boolean = false
        set(value) {
            if (value) {
                collectNum += 1
            } else {
                if (collectNum > 0) {
                    collectNum -= 1
                } else {
                    collectNum = 0
                }
            }
            recommendItem.collect_related = value
            recommendItem.collect_num = collectNum
            field = value
        }
    var isLike:Boolean = false
        set(value) {
            if (value) {
                if (!field) {
                    likeNumber += 1
                }
            } else {
                if (likeNumber > 0) {
                    likeNumber -= 1
                } else {
                    likeNumber = 0
                }
            }
            recommendItem.like_related = value
            recommendItem.like_num = likeNumber
            field = value
        }
    var collectNum: Int = 0
    var likeNumber:Int = 0
    var isReward: Boolean = false
    var rewardNum: Int = 0
    var shareNum: Int = 0
    var isFollow = false

    var cover = ""
    var userInfo: UserInfo
    var description:String

    init {
        userId = recommendItem.user_id
        id = recommendItem.id
        viewNum = recommendItem.view_num
        isCollect = recommendItem.collect_related
        isLike = recommendItem.like_related
        collectNum = recommendItem.collect_num
        likeNumber = recommendItem.like_num
        isReward = recommendItem.reward_related
        rewardNum = recommendItem.reward_num
        shareNum = recommendItem.share_num
        userInfo = recommendItem.user_info
        cover = recommendItem.cover.toString()
        isFollow = userInfo.follow_related != 0
        description = recommendItem.description
    }
}